# encoding: utf-8
require ROOT.join('app', 'api', 'user_api.rb')
require ROOT.join('app', 'api', 'article_api.rb')
require ROOT.join('app', 'api', 'comment_api.rb')
class App < Grape::API
  helpers ::ToolKit
  format :json

  #捕捉所有异常，然后以500的方式输出。再附带上错误信息
  rescue_from :all do |e|
    error_response :status => 500, :message => {:message => e.message, :class => e.class.name, :statck => e.backtrace}.as_json
  end

  after_validation do
    #当前登录用户
    @current_user= session['current_user']
  end

  #装载其他API
  mount UserApi
  mount ArticleApi
  mount CommentApi
end